-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incomplete array alignment in struct #1360
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, somehow github didn't save my review comments.
src/codegen/mod.rs
Outdated
@@ -3658,17 +3658,23 @@ mod utils { | |||
let incomplete_array_decl = quote! { | |||
#[repr(C)] | |||
#[derive(Default)] | |||
pub struct __IncompleteArrayField<T>( | |||
::#prefix::marker::PhantomData<T>); | |||
pub struct __IncompleteArrayField<T>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there's a space missing here.
@@ -0,0 +1,3 @@ | |||
struct bpf_raw_tracepoint_args { | |||
unsigned long long args[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test with another struct with a smaller integer type (like short
, maybe?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good catch. The alignment is still 8 with the current code when I change to a smaller integer type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the pointer alignment is always 8 on 64 bit platform. Ideally, the _alignment field should be [T; 0] but that would prevent automatically implementing Copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, for some reason I thought the should always have pointer alignment... I think [T; 0] is the right thing to do, these structs aren't safe to copy generally anyway.
Hmm, not quite understand the error. Seems that fails at clang not the binding generation. |
☔ The latest upstream changes (presumably #1477) made this pull request unmergeable. Please resolve the merge conflicts. |
I think with repr(align) support and other fixes that have landed in the meantime like #1592 the issue should be fixed. This also is stale. Thanks for the patch (and your other fixes) a lot @photoszzt! |
Fix #1359